<?php

class Note extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return '{{note}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('tableName,foreignKey,content', 'required'),
            array('tsCreated,userIdCreated,tsUpdated,userIdUpdated','safe'),
        );
    }
    // {{{ behaviours
    public function behaviors(){
    	return array(
    		'TimestampBehavior' => array(
    			'class' => 'application.components.behaviors.TimestampBehavior'
    		)
    	);
    } // }}} 
    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'createdBy' => array(self::BELONGS_TO,'User','userIdCreated'),
            'updatedBy' => array(self::BELONGS_TO,'User','userIdUpdated'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id'            => Yii::t('site','ID'),
            'tableName'     => Yii::t('site','Table Name'),
            'foreignKey'    => Yii::t('site','ForeignKey'),
            'content'       => Yii::t('site','Comment'),
            'tsCreated'     => Yii::t('site','Created On'),
            'userIdCreated' => Yii::t('site','Created By'),
            'tsUpdated'     => Yii::t('site','Updated On'),
            'userIdUpdated' => Yii::t('site','Updated By'),
        );
    }
    // {{{ search
    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->order = 'tsCreated DESC';
        $criteria->compare('tableName',$this->tableName,true);
        $criteria->compare('foreignKey',$this->foreignKey,true);
        $criteria->compare('content',$this->content,true);
        $criteria->compare('userIdCreated',$this->userIdCreated,true);
        $criteria->compare('userIdUpdated',$this->userIdUpdated,true);
        $dataProvider = new CActiveDataProvider(get_class($this), array('criteria'=>$criteria));
        return $dataProvider;
    } // }}} 

}
